package com.serviceprovider.business.module.sp.transaction.services.dao.impl;

//~--- non-JDK imports --------------------------------------------------------

import com.serviceprovider.business.module.sp.transaction.model.TransactionStatus;
import com.serviceprovider.business.module.sp.transaction.services.dao.interfaces.ITransStatusDao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

//~--- JDK imports ------------------------------------------------------------

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: akilesa
 * Date: 10-May-2010
 * Time: 1:08:04 PM
 * To change this template use File | Settings | File Templates.
 */
@Repository("transStatusDao")
public class TransStatusDaoImpl extends JdbcDaoSupport implements ITransStatusDao {
    @Autowired
    public TransStatusDaoImpl(@Qualifier("jdbcTemplate") JdbcTemplate jdbcTemplate) {
        setJdbcTemplate(jdbcTemplate);
    }

    // FIXME: should be cached
    public TransactionStatus get(Integer id) {
        String sql = "select * from transaction_status where id=" + id;

        return (TransactionStatus) getJdbcTemplate().queryForObject(sql, new TransStatusMapper());
    }

    @Override
    public TransactionStatus findByName(String name) {
        String sql = "select * from transaction_status where name = '" + name + "'";

        return (TransactionStatus) getJdbcTemplate().queryForObject(sql, new TransStatusMapper());
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<TransactionStatus> findAll() {

        // FIXME: should be cached
        String sql = "select * from transaction_status";

        return getJdbcTemplate().query(sql, new TransStatusMapper());
    }
}



